home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 16 / Mac Magazin and MacEasy Magazine CD - Issue 16.iso / Online / NetCacheBack 0.9d5 ƒ / NetCacheBack source < prev    next >
Text File  |  1995-10-26  |  6KB  |  199 lines

  1. -- Netscape™ Cache Back
  2. -- Copyright © 1995 Mizutori Tetsuya
  3.  
  4. -- global constants
  5. copy "" to gCurrentFolder
  6. copy {} to gCacheRecordList
  7.  
  8. tell me to open {}
  9.  
  10. --
  11. on open (docList)
  12.     local currItem
  13.     --
  14.     if docList is {} then set docList to {(choose file)}
  15.     --
  16.     tell me to setupConstants by the first item of docList
  17.     --
  18.     repeat with currItem in docList
  19.         tell me to moveCacheFile against currItem
  20.     end repeat
  21. end open
  22.  
  23. to setupConstants by currentFile
  24.     global gCurrentFolder, gCacheRecordList
  25.     local refFile, cacheRecordList, cachelog, ccacheLog, viewBy
  26.     --
  27.     tell application "Finder" to get the container of currentFile
  28.     copy the result to gCurrentFolder
  29.     --
  30.     copy ((gCurrentFolder as string) & "Cache log") to cachelog
  31.     copy ((gCurrentFolder as string) & "CCache log") to ccacheLog
  32.     --
  33.     tell application "Finder"
  34.         open the gCurrentFolder
  35.         set viewBy to the view of the gCurrentFolder
  36.         if exists the (alias cachelog) then
  37.             if exists the (alias ccacheLog) then
  38.                 if the modification date of the (alias ccacheLog) comes after ¬
  39.                     the modification date of the (alias cachelog) then
  40.                     tell application "NetCacheResolver"
  41.                         open {(alias ccacheLog)}
  42.                         quit
  43.                     end tell
  44.                 end if
  45.             end if
  46.             try
  47.                 set refFile to open for access (alias cachelog)
  48.                 set cacheRecordList to read refFile as list using delimiters return
  49.                 close access refFile
  50.                 tell application "NetCacheResolver"
  51.                     if the viewBy is byDate then
  52.                         sort cacheRecordList by date
  53.                     else if the viewBy is bySize then
  54.                         sort cacheRecordList by size
  55.                     else
  56.                         sort cacheRecordList by name
  57.                     end if
  58.                     set gCacheRecordList to the result
  59.                     quit
  60.                 end tell
  61.             on error
  62.                 tell me to errorMessage for "Can’t read “Cache log” file"
  63.             end try
  64.         else if exists the (alias ccacheLog) then
  65.             tell application "NetCacheResolver"
  66.                 if the viewBy is byDate then
  67.                     resolve {(alias ccacheLog)} with sorted by date
  68.                 else if the viewBy is bySize then
  69.                     resolve {(alias ccacheLog)} with sorted by size
  70.                 else
  71.                     resolve {(alias ccacheLog)} with sorted by name
  72.                 end if
  73.                 set gCacheRecordList to the result
  74.                 quit
  75.             end tell
  76.         else
  77.             tell me to errorMessage for "Can’t find “Cache log” or “CCache log” file"
  78.         end if
  79.     end tell
  80. end setupConstants
  81.  
  82. to moveCacheFile against cacheFile
  83.     global gCurrentFolder, gCacheRecordList
  84.     local refFile
  85.     local cacheRecord, cachefolder, cacheName
  86.     local url, urlFolder, urlName
  87.     local n
  88.     --
  89.     tell application "Finder"
  90.         copy the container of cacheFile to cachefolder
  91.         copy the name of cacheFile to cacheName
  92.     end tell
  93.     --
  94.     set n to 1
  95.     repeat with cacheRecord in gCacheRecordList
  96.         if cacheName is in the cacheRecord then
  97.             tell me to renameCacheFile(cachefolder, cacheName, cacheRecord)
  98.             set the item n of gCacheRecordList to ""
  99.             exit repeat
  100.         end if
  101.         set n to n + 1
  102.     end repeat
  103.     
  104. end moveCacheFile
  105.  
  106. to renameCacheFile(cachefolder, cacheName, cacheRecord)
  107.     global gCurrentFolder, gCacheRecordList
  108.     local oldDelimiters, cacheItems, cacheFilePath
  109.     local url, urlFolder, urlName, urlItems
  110.     local targetFolderPath, fileType
  111.     --
  112.     copy the text item delimiters to oldDelimiters
  113.     --
  114.     tell me to set the text item delimiters to {tab}
  115.     copy every text item in cacheRecord to cacheItems
  116.     copy the 6th item of cacheItems to fileType
  117.     copy the 5th item of cacheItems to url
  118.     
  119.     tell me to set the text item delimiters to {"/"}
  120.     copy every text item in url to urlItems
  121.     copy (items 3 through -2 in urlItems) to urlFolder
  122.     copy the last item in urlItems to urlName
  123.     tell me to set the text item delimiters to {""}
  124.     if urlName is "" then set the urlName to "index.html"
  125.     if urlName contains "#" then ¬
  126.         copy characters 1 thru ((offset of "#" in urlName) - 1) in urlName as string ¬
  127.             to urlName
  128.     
  129.     tell me to set the text item delimiters to {":"}
  130.     copy ((cachefolder as string) & cacheName) to cacheFilePath
  131.     copy ((gCurrentFolder as string) & (urlFolder as string)) to targetFolderPath
  132.     
  133.     tell me to attachFolder at targetFolderPath as string
  134.     tell me to setFileAttribute of (alias cacheFilePath) by fileType
  135.     tell application "Finder"
  136.         try
  137.             move alias cacheFilePath to the folder targetFolderPath
  138.             if the file urlName in the folder targetFolderPath exists then error
  139.             set the name of file cacheName in the folder targetFolderPath to urlName
  140.         on error
  141.             display dialog "Can’t move “" & cacheName & "” to " & targetFolderPath ¬
  142.                 buttons {"OK"} default button 1 with icon caution
  143.         end try
  144.     end tell
  145.     --
  146.     copy oldDelimiters to the text item delimiters
  147. end renameCacheFile
  148.  
  149. to attachFolder at pathName -- as string
  150.     local listFolders, numbFolders, parentFolder, targetFolder
  151.     --
  152.     tell application "Finder"
  153.         if pathName is "" then
  154.             return path to desktop -- case of the Desktop
  155.         else if the folder pathName exists then
  156.             return the folder pathName -- case of the Folder
  157.         else if the disk pathName exists then
  158.             return the disk pathName -- case of the Volume
  159.         else
  160.             --beep
  161.             tell me to set the text item delimiters to {":"}
  162.             copy every text item of pathName to the listFolders
  163.             copy (the count of items in the listFolders) to the numbFolders
  164.             if listFolders ends with {""} then ¬
  165.                 copy the numbFolders - 1 to the numbFolders
  166.             copy the item numbFolders in the listFolders to targetFolder
  167.             copy (every item in (items 1 thru (numbFolders - 1) in the listFolders)) & {""} ¬
  168.                 to parentFolder
  169.             tell me to attachFolder at the parentFolder as string
  170.             make new folder at the result with properties {name:targetFolder}
  171.             return the result
  172.         end if
  173.     end tell
  174. end attachFolder
  175.  
  176.  
  177. to setFileAttribute of fileRef by fileType
  178.     tell application "Finder"
  179.         if fileType contains "text/html" then
  180.             set the file type of fileRef to "TEXT"
  181.             set the creator type of fileRef to "MOSS"
  182.         else if fileType contains "text/plain" then
  183.             set the file type of fileRef to "TEXT"
  184.             set the creator type of fileRef to "ttxt"
  185.         else if fileType contains "image/gif" then
  186.             set the file type of fileRef to "GIFf"
  187.             set the creator type of fileRef to "JVWR"
  188.         else if fileType contains "image/jpeg" then
  189.             set the file type of fileRef to "JPEG"
  190.             set the creator type of fileRef to "JVWR"
  191.         end if
  192.     end tell
  193. end setFileAttribute
  194.  
  195. on errorMessage for errString
  196.     error errString
  197. end errorMessage
  198.  
  199.